import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';

class LYDataBaseManager {
  static const String _dbName = "ly_database.db";
  final _version = 1;
  late Database _db;
  LYDataBaseManager._internal();
  static final LYDataBaseManager _instance = LYDataBaseManager._internal();
  static LYDataBaseManager get share {
    return _instance;
  }

  void initDatabase() async {
    final databasesPath = await getDatabasesPath();
    final path = join(databasesPath, _dbName);
    _db = await openDatabase(path, version: _version);
  }

  void createTable(String tableName, String sql) async {
    await _db.execute('CREATE TABLE IF NOT EXISTS $tableName ($sql)');
  }

  void insertOrReplaceData(
      String tableName, Map<String, Object?> values) async {
    await _db.insert(tableName, values,
        conflictAlgorithm: ConflictAlgorithm.replace);
  }

  void queryData(String tableName) async {
    _db.query(tableName);
  }
}
